﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MyMaster.Master" AutoEventWireup="true"
    CodeBehind="QuestionNaire.aspx.cs" Inherits="FashionMural.Admin.QuestionNaire" %>

<asp:Content ID="Content1" ContentPlaceHolderID="LeftMenu" runat="server">
    <script type="text/javascript">
        var showflag = true;

        function ShowModel(id) {
            switch (id) {
                case 0:
                    {
                        $("#showcurrent")[0].innerText = "问卷调查";
                    } break;
            }
        }

        function initAll() {

//            $("#questionDetailDiv").hide();
            $("#modelInfo").click(
                function () {
                    if (showflag) {
                        $("#modelInfoChild").hide();
                        showflag = false;
                    } else {
                        $("#modelInfoChild").show();
                        showflag = true;
                    }
                }
            );

            ShowModel(0);

            showQeustionUserPage();

            showQuestionUser(1);
        }

        function getAnonymousUsers(index, count) {
            var result = null;
            var date = new Date();
            $.ajax({
                type: "GET",
                async: false,
                dataType: "json",
                url: "/jsserver/questionnaire/users.aspx",
                data: { qindex: index, qcount: count, fresh: date.getMilliseconds() },
                success: function (data) {
                    result = data;
                },
                error: function () {
                    result = null;
                }
            }
   );
            return result;
        }

        function getQuestionUsersCount() {
            var result = null;
            var date = new Date();
            $.ajax({
                type: "GET",
                async: false,
                url: "/jsserver/questionnaire/users/count.aspx",
                data: { fresh: date.getMilliseconds() },
                success: function (data) {
                    result = data;
                },
                error: function () {
                    result = null;
                }
            }
   );
            return result;
        }

        function deleteUserQuestionNaire(id) {
            var date = new Date();
            $.ajax({
                type: "GET",
                async: false,
                url: "/jsserver/questionnaire/delete.aspx",
                data: { qid: id, fresh: date.getMilliseconds() },
                success: function (data) {
                    if (data == "True") {
                        $("#question" + id).remove();
                    }
                },
                error: function () {
                }
            });
        }

        var checked = true;
        function seletedAll(tableId) {
            if (checked) {
                $("#" + tableId + " input[type=checkbox]").attr("checked", true);
                checked = false;
            } else {
                $("#" + tableId + " input[type=checkbox]").attr("checked", false);
                checked = true;
            }
        }

        function deleteSelectedUser(tableId) {
            var checks = $("#" + tableId + " input[type=checkbox]");
            for (i = 0; i < checks.length; i++) {
                if ($(checks[i]).attr("checked")) {
                    var id = $(checks[i]).val();
                    if (id >= 0) {
                        deleteUserQuestionNaire(id);
                    }
                }
            }
        }

        function showQuestionUser(num) {
            var index = (num - 1) * 10;
            var count = 10;
            var data = getAnonymousUsers(index, count);
            if (data != null) {
                var trs = $("#questionlistTr").parent().children();
                if (trs.length > 3) {
                    for (i = 0; i < trs.length - 3; i++) {
                        $(trs[i + 1]).remove();
                    }
                }
                for (i = 0; i < data.length; i++) {
                    $("#questionlistTr").after("<tr id='question" + data[i].Id + "'><td><input type='checkbox' id='checkque" + data[i].Id + "' value='" + data[i].Id +
                    "' /></td><td>" + data[i].UserName + "</td><td><label id='viewdetailque" + data[i].Id + "' class='btn' onclick=\"showQuestionDetial(" + data[i].Id + ")\">查看详细</label><label id='deleteque" + data[i].Id + "' class='btn' onclick=\"deleteUserQuestionNaire(" + data[i].Id + ")\">删除</label></td></tr>");
                }
                $("#separatepage" + num).attr("style", "font-size:15px;color:Red;cursor:pointer;");
            }
        }

        function showQeustionUserPage() {
            var data = getQuestionUsersCount();
            var num = parseInt((data / 10) + 1);
            $("#questionlistPageTd")[0].innerText = "";
            for (i = 1; i <= num; i++) {
                $("#questionlistPageTd").append("<label id='separatepage" + i + "' style='cursor:pointer;text-decoration:underline' onclick=\"showQuestionUser(" + i + ");\">" + i + "</label>&nbsp;&nbsp;");
            }
        }


        function showQuestionDetial(userid) {
            location.href = "/QuestionNaireDetail.aspx?userid="+userid;       
        }

        $().ready(function () {
            initAll();
        });
    </script>
    <div class="leftMenuTitle" id="modelInfo" style="cursor: pointer;">
        模块信息
    </div>
    <ul class="leftMenu" id="modelInfoChild">
        <li><a href="/ModelManage.aspx">用户留言</a></li>
        <li><a href="/ModelManage.aspx">加盟留言</a></li>
        <li><a href="/ModelManage.aspx">友情链接</a></li>
        <li><a href="#" onclick="ShowModel(0)">问卷调查</a></li>
    </ul>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MidContent" runat="server">
    <div id="mainMenu">
        <ul>
            <li><a id="showcurrent" href="#"></a></li>
        </ul>
    </div>
    <div id="main">
        <table id="quesitonlist" class="mainTable">
            <tr id="questionlistTr" style="background-color: #D7D7D7;">
                <th>
                    选择
                </th>
                <th>
                    问卷用户
                </th>
                <th>
                    操作
                </th>
            </tr>
            <tr>
                <td colspan="4">
                    <input type="checkbox" id="seletedall" value="-1" onclick="seletedAll('quesitonlist')" />全选&nbsp;&nbsp;&nbsp;<input
                        type="button" id="deleteallbtn" value="删除选择项" style="cursor: pointer;" onclick="deleteSelectedUser('quesitonlist')" />
                </td>
            </tr>
            <tr>
                <td id="questionlistPageTd" colspan="4">
                </td>
            </tr>
        </table>
    </div>
<%--    <div id="questionDetailDiv" class="jumpdiv-back">
        <div class="jumpdiv-forward">
            <table id="questionDetal">
                <tr>
                    <td style="text-align: center;">
                        <input onclick="$('#questionDetailDiv').hide();" value="退出" style="cursor: pointer;
                            height: 15px; width: 50px;" />
                    </td>
                </tr>
            </table>
        </div>
    </div>--%>
</asp:Content>
